<?php
require_once 'db.php';

// If user is bloked use default image
if (isset($_GET['blocked'])) {
	$image = file_get_contents('./img/default.png');
	echo $image;
}

// Get profilepic based on ID
if(isset($_GET['usrID'])){
	$sql = 'SELECT profilePicture FROM user WHERE userID=:usrID';
	$sth = $db -> prepare ($sql);
	$sth -> bindParam (':usrID', $_GET['usrID']);
	$sth -> execute ();
}
// Get profilepic based on Name
if(isset($_GET['usrName'])){
	$sql = 'SELECT profilePicture FROM user WHERE userName=:usrName';
	$sth = $db->prepare ($sql);
	$sth -> bindParam (':usrName', $_GET['usrName']);
	$sth -> execute ();
}
$row = $sth->fetch ();

header ("Content-type: image/png ");
// If not set, use default
if($row['profilePicture'] == NULL || $row['profilePicture'] == "") {
	$image = file_get_contents('./img/default.png');
	echo $image;
}
else {
	echo $row['profilePicture'];
}
	
?>